<?php 

class BackupController extends Controller{
	public function __init()
	{
	
	}
	public function index()
	{
		$this->display();
	}
	//数据备份
	public function backup()
	{
		$result = Backup::backup(
			array(
			"size" => 200,
			"dir" => C("DB_BACKUP") . date("Ymdhis")
			)
		);
		if ($result['status'] == 'success') {
			$this->success($result['message'], U('index'));
		} else {
			$this->success($result['message'], $result['url'], 0.2);
		}

	}
	//数据库备份列表
	public function backuplist()
	{
		$dir=Dir::tree('Backup');///遍历目录
		$this->assign('dir',$dir);
		$this->display();
	}
	//数据库还原
	public function recovery()
	{
		$dir = C("DB_BACKUP") . Q("dir");
			$result = Backup::recovery(array('dir' => $dir));
		if ($result['status'] == 'success') {
			$this->success($result['message'], U('index'));
		} else {
			$this->success($result['message'], $result['url'], 0.2);
		}

	}
	//删除备份数据库
	public function del()
	{
		$dir=Q('dir');
		$path='backup/'.$dir;
		if (Dir::del($path)) {
			$this->success('删除成功');
		}else{
			$this->error($this->db->error);
		}
	}


}


 ?>